﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace UnionPay
{
    class ComboBoxConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string[] candidates = null;
            if (value != null)
            {
                DataView dv = value as DataView;
                FileTranslator.ForeignKeyConstraint fkc = parameter as FileTranslator.ForeignKeyConstraint;

                candidates = new string[dv.Count];

                for (int i = 0; i < dv.Count; i++ )
                {
                    string str = string.Format("{0} - {1}",
                        new string[] { 
                            dv[i][fkc.OtherTablePrimaryKeyColumnName].ToString(), 
                            dv[i][fkc.OtherTableDisplayColumnName].ToString()}  );

                    candidates[i] = str;
                }
            }

            return candidates;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Convert(value, targetType, parameter, culture);
        }       
    }
}
